Imports DotNetNuke.Entities.Portals
Imports DnnSecurity.Results
Imports DotNetNuke.Entities.Users
Imports DnnSecurity.Passwords

Namespace Checks
    Public Class AuthenticationUser
        Inherits MultilingualBase
        Implements IDnnSecurityCheck

        Public ReadOnly Property DisplayName As String Implements IDnnSecurityCheck.DisplayName
            Get
                Return GetTranslationFor (Me.GetType.Name & ".DisplayName")
            End Get
        End Property

        Private _ShortInfoText As String

        Public ReadOnly Property ShortInfoText() As String Implements IDnnSecurityCheck.ShortInfoText
            Get
                Return GetTranslationFor (Me.GetType.Name & ".ShortInfoText")
            End Get
        End Property

        Public ReadOnly Property Description() As String Implements IDnnSecurityCheck.Description
            Get
                Return GetTranslationFor (Me.GetType.Name & ".Description")
            End Get
        End Property

        Public ReadOnly Property SecurityRiskClassification As SecurityRiskClassification _
            Implements IDnnSecurityCheck.SecurityRiskClassification
            Get
                Dim res As IDnnSecurityResult =
                        Results.OrderByDescending (Function(x) x.SecurityRiskClassification).FirstOrDefault
                If res IsNot Nothing Then
                    Return res.SecurityRiskClassification
                End If

                Return SecurityRiskClassification.Ok
            End Get
        End Property

        Private _results As New List(Of IDnnSecurityResult)

        Public ReadOnly Property Results() As List(Of IDnnSecurityResult) Implements IDnnSecurityCheck.Results
            Get
                Return _results
            End Get
        End Property

        Public Sub Execute (ByVal portalSettings As PortalSettings, ByVal result As IAsyncResult) _
            Implements IDnnSecurityCheck.Execute
            'Dim users As Generic.IEnumerable(Of DotNetNuke.Entities.Users.UserInfo) = UserController.GetUsers(portalSettings.PortalId).Cast(Of DotNetNuke.Entities.Users.UserInfo)()
            'Dim filteredUsers = users.Where(Function(x) x.Membership.Approved = True)
            Dim passwordSecurity As PasswordScore = PasswordValidator.GetPasswordStrength (0)
            _ShortInfoText = passwordSecurity.ToString ("g")

            If passwordSecurity < PasswordScore.Medium Then
                _results.Add (New WeakPassword ("user"))
            End If

            Dim user As UserInfo = UserController.GetUserByName (portalSettings.PortalId, "admin")
            If user IsNot Nothing Then
                _results.Add (New DefaultUsername (user.Username))
            End If
        End Sub

        Public Overloads Sub LoadRessourceFile (ByVal fileName As String) Implements IDnnSecurityCheck.LoadRessourceFile
            MyBase.LoadRessourceFile (fileName)
        End Sub
    End Class
End Namespace

